1   /*
2    * Created on 2004/12/07
3    */
4   package org.apache.velocity.tools.generic.directive;
5   
6   import java.io.IOException;
7   
8   import org.apache.velocity.exception.MethodInvocationException;
9   import org.apache.velocity.exception.ParseErrorException;
10  import org.apache.velocity.exception.ResourceNotFoundException;
11  import org.ieee.shinobu.demo.velocity.AbstractVelocityTestCase;
12  
13  /***
14   * @author skawai
15   */
16  public class IfnotnullTest extends AbstractVelocityTestCase {
17  
18      public void testNull() throws ParseErrorException, MethodInvocationException, ResourceNotFoundException, IOException, Exception {
19          this.getEngine().setProperty("userdirective", Ifnotnull.class.getName());
20          
21          this.setTemplate("" +
22          		"#ifnotnull($null)\n" +
23          		"not null!\n" +
24          		"#set($wasnull = false)\n" +
25          		"#end\n" +
26          		"$wasnull\n" +
27          		"");
28          
29          this.setExpected("" +
30          		"$wasnull\n" +
31          		"");
32          
33          this.assertVelocity();
34      }
35  
36      public void testNotNull() throws ParseErrorException, MethodInvocationException, ResourceNotFoundException, IOException, Exception {
37          this.getEngine().setProperty("userdirective", Ifnotnull.class.getName());
38          
39          this.setTemplate("" +
40          		"#set($null = 'null')" +
41          		"#ifnotnull($null)\n" +
42          		"not null!\n" +
43          		"#set($wasnull = false)\n" +
44          		"#end\n" +
45          		"$wasnull\n" +
46          		"");
47          
48          this.setExpected("" +
49          		"not null!\n" +
50          		"false\n" +
51          		"");
52          
53          this.assertVelocity();
54      }
55  
56      public void testNotBlock() throws MethodInvocationException, ResourceNotFoundException, IOException, Exception {
57          this.getEngine().setProperty("userdirective", Ifnotnull.class.getName());
58          
59          this.setTemplate("" +
60          		"#ifnotnull()\n" +
61          		"Not a block!\n" +
62          		"");
63          
64          this.setExpected("" +
65          		"");
66          
67          try {
68              this.assertVelocity();
69              fail("not a block!");
70          } catch (ParseErrorException expeceted) {
71          }
72      }
73  
74  }